package br.unifor.cct.mia.ga.util;

import java.io.Serializable;


public class HugeScaleGene implements Serializable {

	private static final long serialVersionUID = -457027881540587294L;
	private double[] bits;
	
	public HugeScaleGene(int nBits) {
		bits = new double[nBits];
	}
	
	public int toInt() {
		String binary = "";
		for(int i = 0; i < bits.length; i++) 
			binary += bits[i]+"";
		
		return Integer.parseInt(binary, 2);
	}
	
	public String toString() {
		String ret = "";
		for(int i = 0; i < bits.length; i++) 
			ret += bits[i]+"  ";
		
		return ret;		
	}
	
	public double[] getBits() {
		return bits;
	}


	public void setBits(double[] bits) {
		this.bits = bits;
	}


	public Object clone() {
		HugeScaleGene clone = new HugeScaleGene(bits.length);
		clone.setBits(bits.clone());
		return clone;
	}
	
	public boolean equals(Object obj) {
		if ( obj instanceof HugeScaleGene ) {
			HugeScaleGene param = (HugeScaleGene)obj;
			double[] paramBits = param.getBits();
			for(int i = 0; i < bits.length; i++) {
				if ( bits[i]!=paramBits[i] ) return false;
			}
			return true;
		}
		else {
			return false;
		}		
	}
	
	public int hashCode() {
		return bits.hashCode();
	}
}
